part of YFree;

///字典转json
String yToJson(Object obj) {
  var jsonStr = json.encode(obj).replaceAll("\"{", "{").replaceAll("}\"", "}");
  var containsBR = jsonStr.contains("\\n");
  var containsTab = jsonStr.contains("\\t");
  var containsUnicode = jsonStr.contains("\\u");
  if (containsBR) jsonStr = jsonStr.replaceAll("\\n", YConfig.brString);
  if (containsTab) jsonStr = jsonStr.replaceAll("\\t", YConfig.tabString);
  if (containsUnicode) jsonStr = jsonStr.replaceAll("\\u", YConfig.unicodeString);
  jsonStr = jsonStr.replaceAll("\\", "");
  if (containsBR) jsonStr = jsonStr.replaceAll(YConfig.brString, "\\n");
  if (containsTab) jsonStr = jsonStr.replaceAll(YConfig.tabString, "\\t");
  if (containsUnicode) jsonStr = jsonStr.replaceAll(YConfig.unicodeString, "\\u");
  return jsonStr;
}

///检查为空
bool yIsEmpty(String? content) {
  return content == null || content.isEmpty;
}

///检查非空
bool yIsNotEmpty(String? content) {
  return content != null && content.isNotEmpty;
}

void yCloseInputMethod({BuildContext? context = null}) {
  FocusScope.of(context ?? yPages.last.context).requestFocus(FocusNode());
}
